package org.pizza.dlock.autoconfigure;

import org.pizza.dlock.distributed.lock.RedissonLock;
import org.pizza.dlock.distributed.lock.api.DistributedLock;
import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * @author 高巍
 * @date 2020-01-31 4:55 下午
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({RedissonClient.class})
public class RedissionLockAutoConfiguration {

    @Bean
    @Lazy
    @ConditionalOnMissingBean(DistributedLock.class)
    @ConditionalOnBean(RedissonClient.class)
    DistributedLock distributedLock(RedissonClient redissonClient) {
        return new RedissonLock(redissonClient);
    }


}
